package com.zenghus.prototype.deep;

import java.io.*;
import java.util.Date;

public class TeLunSu extends Milk implements  Cloneable,Serializable{

    TeLunSu(){
        this.name="特仑苏";
        createDate=new Date();
        producerDetail=new MilkProducerDetail();
        producerDetail.name="蒙牛";
        producerDetail.address="中国";
    }

    @Override
    public void showInfo() {
        System.out.println(name+"\t"+createDate);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return this.SerialObject();
    }

    private Object SerialObject(){
        try {
            ByteArrayOutputStream bos=new ByteArrayOutputStream();
            ObjectOutputStream ob=new ObjectOutputStream(bos);
            ob.writeObject(this);

            ByteArrayInputStream bis=new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois=new ObjectInputStream(bis);
            return ois.readObject();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
